package com.orange.wwwapi.controller.user;

import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.user.User;
import com.orange.core.pojo.req.user.UserAvatarUpdateReq;
import com.orange.core.pojo.req.user.UserNicknameUpdateReq;
import com.orange.core.pojo.req.user.UserProfileUpdateReq;
import com.orange.core.service.user.UserService;
import com.orange.core.util.PrincipalUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 个人中心
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    /**
     * 用户账号信息
     */
    @GetMapping("/profile")
    public R<User> getUserProfile() {
        return R.ok(userService.profile(PrincipalUtil.getId()));
    }

    /**
     * 更新用户信息
     */
    @PostMapping("/profile")
    public R<Boolean> updateProfile(@RequestBody UserProfileUpdateReq req) {
        return R.ok(userService.updateProfile(req));
    }

    /**
     * 修改昵称
     */
    @PostMapping("/updateNickname")
    public R<Boolean> updateNickname(@RequestBody UserNicknameUpdateReq req) {
        return R.ok(userService.updateNickname(req));
    }

    /**
     * 上传头像
     */
    @PostMapping("/updateAvatar")
    public R<Boolean> updateAvatar(@RequestBody UserAvatarUpdateReq req) {
        return R.ok(userService.updateAvatar(req));
    }
}
